package com.template.app.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import com.template.app.util.LogUtils;

public class ExceptionHandler implements HandlerExceptionResolver {

	private static final Logger infoLogger = Logger.getLogger(LogUtils.INFO_LOGGER);
	private static final Logger errorLogger = Logger.getLogger(LogUtils.ERROR_LOGGER);

	public ModelAndView resolveException(HttpServletRequest request,
			HttpServletResponse response, Object obj, Exception ex)
	{		
		handle(ex);
		
//		infoLogger.info(LogUtils.getExceptionMessage(ex));
		errorLogger.error(LogUtils.getExceptionMessage(ex));
		
		String error = null;
		
		if (ex instanceof AppException) {
			error = ex.getMessage();
		} else if (ex instanceof ErrorException) {
			error = ex.getMessage();
		} else {
			error = ex.getMessage();
		}
		
		return new ModelAndView("", "error", error);
	}
	
	public static void handle(Exception ex) {
		
	}

}
